﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BigDataFramework.Repositories.Interfaces;
using BigDataFramework.Repositories;
using BigData.DataContracts.Objects.BigData.BaseTypes;

namespace BigData.Controllers.api
{
    public abstract class BaseDataController<T> : ApiController
            where T : BigDataDBObjectBase
    {
        protected IRepository _DbContext { get; set; }

        public BaseDataController()
        {
            this._DbContext = new MongoDBRepository();
        }

        public IQueryable<T> Get()
        {
            return this._DbContext.Read<T>();
        }

        public T Get(string id)
        {
            return this._DbContext.ReadOne<T>(id);
        }

        public void Post([FromBody]T value)
        {
            this._DbContext.Create<T>(value);
        }

        public void Put([FromBody]T value)
        {
            this._DbContext.Update<T>(value);
        }

        public void Delete([FromBody]T value)
        {
            this._DbContext.Delete<T>(value);
        }
    }
}
